package com.sghj.utils.okhttp;//package com.QRcode.common.utils.okhttp;
//
//
//import org.apache.http.HttpRequest;
//import org.apache.http.auth.AuthenticationException;
//import org.apache.http.auth.Credentials;
//import org.apache.http.auth.MalformedChallengeException;
//import org.apache.http.auth.UsernamePasswordCredentials;
//import org.apache.http.impl.auth.DigestScheme;
//import org.apache.http.message.BasicHeader;
//import org.apache.http.message.BasicHttpRequest;
//
//import java.io.IOException;
//
//import okhttp3.Authenticator;
//import okhttp3.Request;
//import okhttp3.Response;
//import okhttp3.Route;
//
///**
// * @author xrx
// * @Date 2024-06-25
// * @apiNote
// */
//public class DigestAuthenticator implements Authenticator {
//
//    DigestScheme mDigestScheme = new DigestScheme();
//    Credentials mCredentials = null;
//
//    public DigestAuthenticator(String username,String password) {
//        mCredentials = new UsernamePasswordCredentials(username, password);
//    }
//
//    @Override
//    public Request authenticate(Route route, Response response) throws IOException {
//        try {
//            mDigestScheme.processChallenge(new BasicHeader("WWW-Authenticate", response.header("WWW-Authenticate")));
//        } catch (MalformedChallengeException e) {
//        }
//
//        HttpRequest request = new BasicHttpRequest(
//                response.request().method(),
//                response.request().url().toString()
//        );
//        String authHeader;
//        try {
//            authHeader = mDigestScheme.authenticate(mCredentials, request).getValue();
//        } catch (AuthenticationException e) {
//            authHeader = null;
//        }
//        if (authHeader == null) {
//            return null;
//        }
//        return response.request().newBuilder().addHeader("Authorization", authHeader).build();
//    }
//}
